<template>
  <div class="home">
    <van-swipe
      class="my-swipe"
      :autoplay="1500"
      indicator-color="white"
    >
      <van-swipe-item
        v-for="item in lunbolist"
        :key="item.id"
      >
        <img
          :src="item.img"
          alt=""
        >
      </van-swipe-item>
    </van-swipe>

    <van-grid :column-num="3">
      <van-grid-item
        v-for="item in grids"
        :key="item.id"
        :icon="item.src"
        :text="item.title"
        :to="item.to"
      />
    </van-grid>
  </div>
</template>
<script>
export default {
  data: () => ({
    lunbolist: [],
    grids: []
  }),
  created() {
    this.getLunbo()
    this.getGrids()
  },
  methods: {
    async getLunbo() {
      try {
        const { data: { message } } = await this.Api.getLunbo()
        this.lunbolist = message
        // console.log(this.lunbolist)
      } catch (error) {
        this.$Toast('轮播图请求失败。。。')
      }
    },
    async getGrids() {
      try {
        const { data: { message } } = await this.Api.getGrids()
        this.grids = message
        // console.log(this.grids)
      } catch (error) {
        this.$Toast('九宫格请求失败。。。')
      }
    }
  }
}
</script>
<style lang='scss' scoped>
  .my-swipe .van-swipe-item{
    height: 200px;
    // background-color: red;
    img{
      width: 100%;
      height: 100%;
    }
  }
</style>
